{% extends "inventory/base.html" %}

{% block title %}库存盘点列表{% endblock %}

{% block content %}
<div class="container">
    <div class="row mb-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center">
                <h1 class="h2">库存盘点</h1>
                <a href="{% url 'inventory_check_create' %}" class="btn btn-primary">
                    <i class="bi bi-plus-circle"></i> 创建盘点
                </a>
            </div>
        </div>
    </div>

    <!-- 搜索和筛选 -->
    <div class="row mb-4">
        <div class="col-md-6">
            <form action="" method="get" class="d-flex">
                <input type="text" name="q" value="{{ search_query }}" class="form-control me-2" placeholder="搜索盘点名称...">
                <button type="submit" class="btn btn-outline-primary">搜索</button>
            </form>
        </div>
        <div class="col-md-6">
            <form action="" method="get" class="d-flex justify-content-md-end">
                <select name="status" class="form-select me-2" style="max-width: 200px;">
                    <option value="">所有状态</option>
                    {% for status_value, status_name in status_choices %}
                    <option value="{{ status_value }}" {% if status_filter == status_value %}selected{% endif %}>{{ status_name }}</option>
                    {% endfor %}
                </select>
                <button type="submit" class="btn btn-outline-primary">筛选</button>
            </form>
        </div>
    </div>

    <!-- 盘点列表 -->
    <div class="row">
        <div class="col-12">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead class="table-dark">
                        <tr>
                            <th>ID</th>
                            <th>名称</th>
                            <th>状态</th>
                            <th>创建人</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for check in inventory_checks %}
                        <tr>
                            <td>{{ check.id }}</td>
                            <td>{{ check.name }}</td>
                            <td>
                                {% if check.status == 'draft' %}
                                <span class="badge bg-secondary">{{ check.get_status_display }}</span>
                                {% elif check.status == 'in_progress' %}
                                <span class="badge bg-primary">{{ check.get_status_display }}</span>
                                {% elif check.status == 'completed' %}
                                <span class="badge bg-info">{{ check.get_status_display }}</span>
                                {% elif check.status == 'approved' %}
                                <span class="badge bg-success">{{ check.get_status_display }}</span>
                                {% elif check.status == 'cancelled' %}
                                <span class="badge bg-danger">{{ check.get_status_display }}</span>
                                {% endif %}
                            </td>
                            <td>{{ check.created_by.username }}</td>
                            <td>{{ check.created_at|date:"Y-m-d H:i" }}</td>
                            <td>
                                <a href="{% url 'inventory_check_detail' check_id=check.id %}" class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-eye"></i> 查看
                                </a>
                                
                                {% if check.status == 'draft' %}
                                <a href="{% url 'inventory_check_start' check_id=check.id %}" class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-play-fill"></i> 开始盘点
                                </a>
                                {% endif %}
                                
                                {% if check.status == 'in_progress' %}
                                <a href="{% url 'inventory_check_complete' check_id=check.id %}" class="btn btn-sm btn-outline-success">
                                    <i class="bi bi-check-circle"></i> 完成盘点
                                </a>
                                {% endif %}
                                
                                {% if check.status == 'completed' %}
                                <a href="{% url 'inventory_check_approve' check_id=check.id %}" class="btn btn-sm btn-outline-info">
                                    <i class="bi bi-shield-check"></i> 审核
                                </a>
                                {% endif %}
                                
                                {% if check.status != 'approved' and check.status != 'cancelled' %}
                                <a href="{% url 'inventory_check_cancel' check_id=check.id %}" class="btn btn-sm btn-outline-danger" 
                                   onclick="return confirm('确定要取消此盘点吗？')">
                                    <i class="bi bi-x-circle"></i> 取消
                                </a>
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="6" class="text-center py-4">没有找到库存盘点记录</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %} 